package com.deer.wms.ware.task.model.SO;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Objects;

/**
 * @author guo
 */
@Getter
@Setter
@Table(name = "so_detail")
public class SoDetail {
    /**
     * 主键
     */
    @Id
    @TableId(type = IdType.AUTO)
    @Column(name = "so_detail_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer soDetailId;

    private Integer soMasterId;
    /**
     * 单号
     */
    @Column(name = "bill_no")
    private String billNo;

    /**
     * 详情单号
     */
    @Column(name = "detail_no")
    private String detailNo;

    /**
     * 状态 0-新建
     */
    private Integer state;

    /**
     * 物料编码
     */
    @Column(name = "item_code")
    private String itemCode;

    /**
     * 物料名称
     */
    @Column(name = "item_name")
    private String itemName;

    /**
     * 物料规格
     */
    @Column(name = "spec")
    private String spec;

    /**
     * 物料型号
     */
    @Column(name = "model")
    private String model;

    /**
     * 物料名称
     */
    @Column(name = "img_url")
    private String imgUrl;

    /**
     * 包装详情ID
     */
    @Column(name = "pack_detail_id")
    private Integer packDetailId;

    /**
     * 包装描述
     */
    @Column(name = "pack_describe")
    private String packDescribe;


    private Double transRatio;
    /**
     * 订货数
     */
    @Column(name = "order_quantity")
    private Double orderQuantity;

    /**
     * 预分配数
     */
    @Column(name = "expect_allotted_quantity")
    private Double expectAllottedQuantity;

    /**
     * 分配数
     */
    @Column(name = "allotted_quantity")
    private Double allottedQuantity;

    private Integer allotPackDetailId;
    private String allotPackDescribe;
    private Double allotTransRatio;
    /**
     * 拣货数量
     */
    @Column(name = "pick_quantity")
    private Double pickQuantity;

    private Integer pickPackDetailId;
    private String pickPackDescribe;
    private Double pickTransRatio;
    /**
     * 发货数量
     */
    @Column(name = "delivery_quantity")
    private Double deliveryQuantity;

    public Double getDeliveryQuantity() {
      return   ObjectUtil.isEmpty(deliveryQuantity) ? 0.00 : deliveryQuantity;
    }

    private Double checkQuantity;



    private Integer deliveryPackDetailId;
    private String deliveryPackDescribe;
    private Double deliveryTransRatio;
    /**
     * 自定义1
     */
    @Column(name = "so_udf_ds1")
    private String soUdfDs1;

    /**
     * 自定义2
     */
    @Column(name = "so_udf_ds2")
    private String soUdfDs2;

    /**
     * 自定义3
     */
    @Column(name = "so_udf_ds3")
    private String soUdfDs3;

    /**
     * 备注
     */
    private String memo;

    /**
     * ERP源单id
     */
    @Column(name = "erp_bill_id")
    private Integer erpBillId;

    public String getMemo() {
      return   String.format("%s-%s", this.itemCode, this.rob);
//       return this.itemCode + this.rob;
    }

    private String mergeNo;
    private Double weight;
    private Double size;
    private Integer bomSplit;
    private String allotDetailNo;
    @TableField(exist = false)
    private Double number;
    @TableField(exist = false)
    @ApiModelProperty("库存余量")
    private Double marginQty;

    /**
     * 波次明细ID
     */
    private Integer waveDetailId;
    @TableField(exist = false)
    @ApiModelProperty("基本单位原始数量")
    private Double originQty;

    @ApiModelProperty("基本待检验数量")
    @TableField(exist = false)
    private Double qcQty;
    /**
     * 目标红蓝字
     */
    @Column(name = "rob")
    private Boolean rob;

    @TableField(exist = false)
    private String orderBillNo;


    //合计库存数量
    @TableField(exist = false)
    private Double totalNum;

    //行号
    private String uda1;

    //退货对象客户
    private String wldwNo;

    //制单员工号
    private String makeEmpNo;

    //退货数量
    private Double qtyTrans;

    //退补数量
    private Double qtyOrderTrans;

    //退扣数量
    private Double qtyArTrans;

    //退货单位
    private String unitName;

    //组织id
    private Long org;
    //创建时间
    private String createTime;
    //仓库编码
    private String wareCode;
    //状态
    private int status;
    //申请类型
    private String typeNo;
    //生产订单号
    private String moCode;
    //生产订单备料ID
    private String moPick;
    //调入存储地点
    private String inWhCode;
    //调出存储地点
    private String outWhCode;
    //单据ID
    private Long documentsId;
    //单行ID
    private Long erpLine;
    //单行号
    private int erpLineNo;
    //收货单据号
    private String srcDocNo;
    //收货单行ID
    private Long srcDocLine;
    //收货单行号
    private int srcDocLineNo;
    //生产订单ID
    private Long mo;
    //存储地点编码
    private String whCode;

    @TableField(exist = false)
    private String areaCode;

    /**
     * 聚源数量
     */
    @TableField(exist = false)
    private Double qty;
    /**
     * 聚源调出仓库
     */
    @TableField(exist = false)
    private Integer stockId;
    /**
     * 聚源批号
     */
    @TableField(exist = false)
    private String batchName;
    @TableField(exist = false)
    /**
     * 聚源调入仓库id
     */
    private Integer toStockId;



    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SoDetail soDetail = (SoDetail) o;
        return billNo.equals(soDetail.billNo) && erpBillId.equals(soDetail.erpBillId) && bomSplit.equals(soDetail.bomSplit) && itemCode.equals(soDetail.getItemCode());
    }

    @Override
    public int hashCode() {
        return Objects.hash(billNo, erpBillId, bomSplit,itemCode);
    }
}